#include "board.h"
#include "rtthread.h"

static void Receive_Thread_Rntry(void* parameter);
static void Send_Thread_Entry(void* parameter);

static rt_thread_t receive_thread = RT_NULL;
static rt_thread_t send_thread = RT_NULL;

static rt_sem_t test_sem = RT_NULL;

uint8_t ucValue [ 2 ] = { 0x00, 0x00 };

int main(void)
{	
		ILI9341_GramScan ( 6 );//设置显示模式
		LED_Color(LED_OFF);
		test_sem = rt_sem_create("test",1,RT_IPC_FLAG_FIFO);
	
    receive_thread = 
			rt_thread_create("receive_thread",Receive_Thread_Rntry,RT_NULL,512,3,20);
	  rt_thread_startup(receive_thread);
	
		send_thread = 
				rt_thread_create("send_thread",Send_Thread_Entry,RT_NULL,512,3,20);
		rt_thread_startup(send_thread);	
}

static void Receive_Thread_Rntry(void* parameter)
{
	rt_err_t uwRet = RT_EOK;
	uint32_t r_queue;
	while(1)
	{
		rt_sem_take(test_sem,RT_WAITING_FOREVER);
		if(ucValue [ 0 ] == ucValue [ 1 ])
		{
			rt_kprintf("Successful\n");
		}
		else
		{
			rt_kprintf("Fail\n");
		}
		rt_sem_release( test_sem );
		rt_thread_delay(1000);
	}
}

static void Send_Thread_Entry(void* parameter)
{

	while(1)
	{
		rt_sem_take(test_sem,RT_WAITING_FOREVER);
		ucValue [ 0 ] ++;
		rt_thread_delay ( 5000 ); /* 延时 100ms */
		ucValue [ 1 ] ++;
		rt_sem_release(test_sem); //释放二值信号量
		rt_thread_yield(); //放弃剩余时间片，进行一次线程切换
	}
}
